package main

import "fmt"

/*
//使用golang 实现链表的反转
1，2，3，4
*/

type SingleList struct {
	elem int
	next *SingleList
}

func Reverse(head *SingleList) *SingleList{
	beg := head.next
	var end *SingleList = beg.next

	for end != nil{
		beg.next = end.next
		end.next = head.next
		head.next = end
		end = beg.next
	}

	return head
}

func main(){
	l4 := SingleList{elem: 4, next: nil}
	l3 := SingleList{elem: 3, next: &l4}
	l2 := SingleList{elem: 2, next: &l3}
	l1 := SingleList{elem: 1, next: &l2}
	head := SingleList{next: &l1}
	L := Reverse(&head)
	for L != nil{

		fmt.Printf("%d\t",L.elem)
		L = L.next
	}
}






